import java.util.*;

public class TextDemo {
    public boolean isNumber(String str){
        return !((str.equals("+"))||(str.equals("-"))||(str.equals("*"))||(str.equals("/")));
    }

    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(int i = 0;i<tokens.length;i++){
            String token = tokens[i];
            if(isNumber(token)){
                stack.push(Integer.parseInt(token));
            }else{
                int num1 = stack.pop();
                int num2 = stack.pop();
                switch (token)
                {
                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                        break;

                }
            }
        }
        return stack.peek();
    }
    public int[] dailyTemperatures(int[] temperatures) {

        int[] ans = new int[temperatures.length];
        Stack<Integer> stack = new Stack<>();
        for(int i = 0;i<temperatures.length;i++){
            if(stack.empty()||temperatures[i]<temperatures[stack.peek()]){
                stack.push(i);
            }else{
                while(!stack.empty()&&temperatures[i]>temperatures[stack.peek()]){
                    ans[stack.peek()] = i-stack.peek();
                    stack.pop();
                }
                stack.push(i);
            }
        }
        return ans;

    }
    public int[] nextGreaterElement1(int[] nums1, int[] nums2) {
        Stack<Integer> stack = new Stack<>();
        HashMap<Integer,Integer> map = new HashMap<>();
        for(int i = 0;i< nums2.length;i++){
            int num = nums2[i];
          while(!stack.isEmpty()&&stack.peek()<num){
              map.put(stack.pop(), num);
          }
          stack.push(num);
        }
        while(!stack.isEmpty()){
            map.put(stack.pop(), -1);
        }
        for(int i = 0;i<nums1.length;i++){
            nums1[i] = map.get(nums1[i]);
        }
        return nums1;
    }
    public int[] nextGreaterElement2(int[] nums1, int[] nums2) {
        Stack<Integer> stack = new Stack<>();
        HashMap<Integer,Integer> map = new HashMap<>();
        for(int i = nums2.length-1;i>=0;i--){
            int num = nums2[i];
           while(!stack.isEmpty()&&num>stack.peek()){
               stack.pop();
           }
           map.put(num,stack.isEmpty()?-1:stack.peek());
           stack.push(num);
        }
        return nums1;
    }
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        Stack<Integer> stack = new Stack<>();
        HashMap<Integer,Integer> map = new HashMap<>();
        for(int i = 0;i<nums2.length;i++){
            int num = nums2[i];
            while(!stack.isEmpty()&&num>stack.peek()){

            }
            stack.push(num);

        }
        return nums1;
    }
    }






















